<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Card\Model;
use Think\Model;

/**
 * 用户模型
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */

class CardIdModel extends Model {

    public $sx_data = array();

    protected $_validate = array(
        //只在注册时验证
        array('user_id','','用户id不能为空',1,'notequal',1),
        array('cart_id','','名片id不能为空',1,'notequal',1),
    );

    /**
     * 查询单条id信息
     */
    public function getCidInfo($condition, $field = '*') {
        return $this->field($field)->where($condition)->find();
    }

    /**
     * 新增id
     */
    public function addCardId(){
        if (!$this->create($this->sx_data,1)){
            $res['msg'] = $this->getError();
            $res['sta'] = -1;
            return $res;
        }else{
            $res = $this->add();
            return $res;
        }

    }

    /**
     * 增加照片
     */
    public function saveCart($condition,$data){
        if(empty($condition)){
            return false;
        }
        $res = $this->where($condition)->save($data);
        return $res;
    }
    
    public function getUserId($cardId)
    {
        return M('card_id')->where([
            'cart_id' => $cardId
        ])->getField('user_id');
    }

}
